package com.dalitek.sampleface;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.Toast;

import com.dalitek.sampleface.config.capture.CaptureConfig_1v1;
import com.dalitek.sampleface.config.capture.CaptureConfig_1vn;
import com.dalitek.sampleface.config.capture.CaptureConfig_nvn;
import com.oliveapp.face.libfacecapture.x.entity.BaseCaptureConfigEntity;
import com.oliveapp.libcommon.utility.LogUtil;

import java.io.InputStream;
import java.util.Properties;


public class BaseActivity extends Activity {
    private final String TAG = BaseActivity.class.getSimpleName();
    protected Context bContext;
    protected Activity bActivity;
    private ActivityManager activityManager;
    protected static BaseCaptureConfigEntity captureConfig_1v1 = CaptureConfig_1v1.getInstance();
    protected static BaseCaptureConfigEntity captureConfig_1vn = CaptureConfig_1vn.getInstance();
    protected static BaseCaptureConfigEntity captureConfig_nvn = CaptureConfig_nvn.getInstance();
    protected String activateCode = "";
    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bActivity = this;
        bContext = this;
        activityManager=  (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        Properties proper = getProperties(bContext);
        activateCode = proper.getProperty("activateCode");
        LogUtil.e(TAG,activateCode);

    }
    protected void toast(String text){
        runOnUiThread(() -> Toast.makeText(bContext,text, Toast.LENGTH_SHORT).show());
    }

    private ProgressDialog progressDialog;

    public void showLoadingDialog() {
        progressDialog = new ProgressDialog(bContext);
        // 设置进度条的形式为圆形转动的进度条
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

        progressDialog.setCancelable(true);// 设置是否可以通过点击Back键取消
        progressDialog.setCanceledOnTouchOutside(false);// 设置在点击Dialog外是否取消Dialog进度条
        // 设置提示的title的图标，默认是没有的，如果没有设置title的话只设置Icon是不会显示图标的
        progressDialog.setTitle("加载中...");
        progressDialog.show();
    }

    public void dismissLoadingDialog() {
        if (null != progressDialog && progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
    }

    private  Properties getProperties(Context c){
        Properties urlProps;
        Properties props = new Properties();
        try {
            InputStream in = c.getAssets().open("config");
            props.load(in);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        urlProps = props;
        return urlProps;
    }

}
